package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryTrademark;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTradeMarkService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: BaseCategoryTradeMarkController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-08-18 22:16
 * @Version 1.0
 */

@Api(tags = "分类与品牌管理")
@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTradeMarkController {
@Autowired
// category 分类 trademark 品牌
private BaseCategoryTradeMarkService baseCategoryTradeMarkService;

 /**
  * 根据三级分类Id 获取到可选品牌列表。
  * @param category3Id
  * @return
  */
 @ApiOperation("根据category3Id获取品牌列表")
 @GetMapping("/findTrademarkList/{category3Id}")
 public Result findTrademarkList(@PathVariable Long category3Id){
  List<BaseTrademark> baseTrademarkList = baseCategoryTradeMarkService.findTrademarkList(category3Id);
  return Result.ok(baseTrademarkList);
 }
 /**
  * 根据三级分类Id获取到可选品牌列表
  * @param category3Id
  * @return
  */
 @GetMapping("/findCurrentTrademarkList/{category3Id}")
 public Result findCurrentTrademarkList (@PathVariable Long category3Id){
  //  服务层方法.
  List<BaseTrademark>  baseTrademarkList = this.baseCategoryTradeMarkService.findCurrentTrademarkList(category3Id);
  //  返回数据
  return Result.ok(baseTrademarkList);
 }

 /**
  * 保存分类Id 与 品牌的关系
  * @param categoryTrademarkVo
  * @return
  */
 @PostMapping("/save")
 public Result save(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
  //  调用服务层方法.
  this.baseCategoryTradeMarkService.save(categoryTrademarkVo);
  return Result.ok();
 }
 /**
  * 删除品牌与分类的关系
  * @param category3Id
  * @param trademarkId
  * @return
  */
 @DeleteMapping("/remove/{category3Id}/{trademarkId}")
 public Result remove(@PathVariable Long category3Id,
                      @PathVariable Long trademarkId) {

  this.baseCategoryTradeMarkService.remove(category3Id,trademarkId);

  return Result.ok();
 }
}
